package com.smedi.ismedi.constructionproject.core.port.adapter.persistence.repository.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.smedi.ismedi.constructionproject.core.domain.aggregatemodel.BidSectionConfig;
import com.smedi.ismedi.constructionproject.core.domain.repository.BidSectionConfigRepository;
import com.smedi.ismedi.constructionproject.core.port.adapter.persistence.model.BidSectionConfigEntity;
import com.smedi.ismedi.constructionproject.core.port.adapter.persistence.mybatis.mapper.BidSectionConfigMapper;
import com.smedi.ismedi.web.starter.util.DozerUtil;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @Author: xulinjun
 * @Date: 2021-6-18 15:54
 */
@Slf4j
@Repository
@AllArgsConstructor
public class BidSectionConfigRepositoryImpl extends ServiceImpl<BidSectionConfigMapper, BidSectionConfigEntity> implements BidSectionConfigRepository, IService<BidSectionConfigEntity> {
    private final DozerUtil dozerUtil;

    @Override
    public void deleteByBidSectionId(Long bidSectionId) {
        QueryWrapper<BidSectionConfigEntity> wrapper = new QueryWrapper();
        wrapper.eq("bid_section_id", bidSectionId);
        this.getBaseMapper().delete(wrapper);
    }

    @Override
    public BidSectionConfig doInsert(BidSectionConfig bidSectionConfig) {
        BidSectionConfigEntity bidSectionConfigEntity = dozerUtil.convertor(bidSectionConfig, BidSectionConfigEntity.class);
        this.getBaseMapper().insert(bidSectionConfigEntity);
        return dozerUtil.convertor(bidSectionConfigEntity, BidSectionConfig.class);
    }

    @Override
    public List<BidSectionConfig> selectListByBidSectionIdOrderById(Long bidSectionId) {
        QueryWrapper<BidSectionConfigEntity> wrapper = new QueryWrapper();
        wrapper.eq("bid_section_id", bidSectionId)
                .orderByAsc("id");
        List<BidSectionConfigEntity> list = this.getBaseMapper().selectList(wrapper);
        return dozerUtil.convertor(list, BidSectionConfig.class);
    }
}
